package cn.aran.org.service.impl;

import cn.aran.basic.util.PageList;
import cn.aran.org.domain.Department;
import cn.aran.org.mapper.DepartmentMapper;
import cn.aran.org.query.DepartmentQuery;
import cn.aran.org.service.IDepartmentService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @Description: 实现类
* @Author: Aran
* @Version: 1.0
* @Date:  2022/6/21 18:41
*/
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    /*
    * @Title: loadAll
    * @Description: 查询全部部门
    * @Author: Aran
    * @Version: 1.0
    * @Date:  2022/6/21 18:44
    * @Parameters: []
    * @Return java.util.List<cn.aran.org.domain.Department>
    */
    @Override
    public List<Department> loadAll() {
        return departmentMapper.loadAll();
    }

    /*
    * @Title: loadById
    * @Description: T根据id查询部门
    * @Author: Aran
    * @Version: 1.0
    * @Date:  2022/6/21 18:44
    * @Parameters: [id]
    * @Return cn.aran.org.domain.Department
    */
    @Override
    public Department loadById(Long id) {
        return departmentMapper.loadById(id);
    }

    /*
    * @Title: remove
    * @Description: 部门删除
    * @Author: Aran
    * @Version: 1.0
    * @Date:  2022/6/21 18:44
    * @Parameters: [id]
    * @Return void
    */
    @Transactional
    @Override
    public void remove(Long id) {
        departmentMapper.remove(id);
    }

    /*
    * @Title: save
    * @Description: 部门新增
    * @Author: Aran
    * @Version: 1.0
    * @Date:  2022/6/21 18:44
    * @Parameters: [department]
    * @Return void
    */
    @Transactional
    @Override
    public void save(Department department) {
        departmentMapper.save(department);
    }

    /*
    * @Title: update
    * @Description: 部门修改
    * @Author: Aran
    * @Version: 1.0
    * @Date:  2022/6/21 18:44
    * @Parameters: [department]
    * @Return void
    */
    @Transactional
    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    /*
    * @Title: queryData
    * @Description: 部门高级查询
    * @Author: Aran
    * @Version: 1.0
    * @Date:  2022/6/21 18:45
    * @Parameters: [departmentQuery]
    * @Return cn.aran.basic.util.PageList<cn.aran.org.domain.Department>
    */
    @Override
    public PageList<Department> queryData(DepartmentQuery departmentQuery) {
        Integer total = departmentMapper.queryCount(departmentQuery);
        List<Department> rows = departmentMapper.queryData(departmentQuery);
        return new PageList<>(total, rows);
    }
}
